# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=librevenge
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=0.0.5
pkgrel=1
pkgdesc="Library for REVerses ENGineered formats filters (mingw-w64)"
arch=('any')
mingw_arch=('mingw64' 'ucrt64' 'clang64' 'clangarm64')
url="https://sourceforge.net/p/libwpd/librevenge/"
license=("spdx:MPL-2.0 OR LGPL-2.1-or-later")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-autotools"
             "${MINGW_PACKAGE_PREFIX}-doxygen"
             "${MINGW_PACKAGE_PREFIX}-boost"
             "${MINGW_PACKAGE_PREFIX}-cppunit")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-zlib")
source=("https://sourceforge.net/projects/libwpd/files/librevenge/${_realname}-${pkgver}/${_realname}-${pkgver}.tar.xz")
sha256sums=('106d0c44bb6408b1348b9e0465666fa83b816177665a22cd017e886c1aaeeb34')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  # For WARNING: 'automake-1.15' is probably too old.
  WANT_AUTOMAKE=latest autoreconf -fiv
}

build() {
  [[ -d "${srcdir}/build-${MSYSTEM}" ]] && rm -rf "${srcdir}/build-${MSYSTEM}"
  cp -r "${srcdir}/${_realname}-${pkgver}" "${srcdir}/build-${MSYSTEM}"
  cd "${srcdir}/build-${MSYSTEM}"

  declare -a _extra_config
  if check_option "debug" "y"; then
    _extra_config+=("--enable-debug")
  fi

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST} \
    "${_extra_config[@]}" \
    --disable-werror \
    --enable-shared \
    --enable-static \
    --enable-tests \
    --with-docs=yes

  make
}

check() {
  cd "${srcdir}/build-${MSYSTEM}"
  make check || true
}

package() {
  cd "${srcdir}/build-${MSYSTEM}"
  make DESTDIR="${pkgdir}" install
  find "${pkgdir}${MINGW_PREFIX}" -name '*.def' -o -name '*.exp' | xargs -rtl1 rm

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.LGPL" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.LGPL"
  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING.MPL" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING.MPL"
}
